// ml:run = time -p $bin < input
// ml:opt = 0
// ml:ccf += -g
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

struct edge { int x, y; };
using graph_type = std::vector<std::vector<int>>;

int const maxn = 507;
int const maxm = 10007;
int father[maxn];
int vis[maxm];
int n, m, q;

graph_type tree;
std::vector<edge> edges;

std::vector<std::vector<int>> pr; // path to root that edges form a spanning tree

void init_father()
{
    for (int i = 0; i <= n; i++) father[i] = i;
}

int get_father(int x)
{
    return x == father[x] ? x : (father[x] = get_father(father[x]));
}

void init()
{
    tree.clear(); tree.resize(m + 1);
    pr.clear(); pr.resize(m + 1);
    edges.resize(m + 1);
    std::memset(vis, 0, sizeof(vis));
}

void add_edge(int u, int v, graph_type & g)
{
    g[u].push_back(v);
    g[v].push_back(u);
}

void dfs(int u, int f, std::vector<int> & p)
{
    int tn = p.size();
    int bf[n + 1];
    for (int i = 1; i <= n; i++) bf[i] = father[i];
    int tu = get_father(edges[u].x);
    int tv = get_father(edges[u].y);
    if (tu != tv) {
        p.push_back(u);
        father[tu] = tv;
    }
    pr[u] = p;
    for (auto v : tree[u]) {
        if (v == f) continue;
        dfs(v, u, p);
    }
    p.resize(tn);
    for (int i = 1; i <= n; i++) father[i] = bf[i];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ":\n";
        std::cin >> n >> m;
        init();
        for (int i = 2; i <= m; i++) {
            int x; std::cin >> x;
            add_edge(x, i, tree);
        }
        for (int i = 1; i <= m; i++)
            std::cin >> edges[i].x >> edges[i].y;

        std::vector<int> v;
        init_father();
        dfs(1, 0, v);

        /* for (int i = 1; i <= m; i++) { */
        /*     std::cout << i << " : "; */
        /*     for (auto j : pr[i]) std::cout << " " << j; */
        /*     std::cout << "\n"; */
        /* } */

        std::cin >> q;
        for (int i = 0; i < q; i++) {
            int k; std::cin >> k;
            init_father();
            int ans = n;
            for (int j = 0, x; j < k; j++) {
                std::cin >> x;
                /* if ((int)pr[x].size() > n) exit(1); */
                for (int tt = pr[x].size() - 1; tt >= 0; tt--) {
                    int t = pr[x][tt];
                    if (vis[t] == i + 1) break;
                    int tu = get_father(edges[t].x);
                    int tv = get_father(edges[t].y);
                    if (tu != tv) {
                        ans--;
                        father[tu] = tv;
                    }
                    vis[t] = i + 1;
                }
            }
            std::cout << ans << "\n";
        }
    }
}

